package tenant

import (
	"context"
	"git.mycaigou.com/gfyx/common/rpc_client"
	"git.mycaigou.com/gfyx/micro-gfyx-api/infrastructure/common/constants"
	microGfyxUserService "git.mycaigou.com/gfyx/micro-gfyx-api/proto/micro_gfyx_user_service_proto/micro-gfyx-user-service/tenant"
)

type TenantRepository struct {
}

func NewTenantRepository() TenantRepositoryIface {
	return &TenantRepository{}
}

func (t TenantRepository) GetTenantList(ctx context.Context, request *microGfyxUserService.GetTenantListRequest) (*microGfyxUserService.GetTenantListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_USER_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()

	client := microGfyxUserService.NewTenantServiceClient(conn)
	response, err := client.GetTenantList(ctx, request)
	if err != nil {
		return nil, err
	}
	return response, err
}
